#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT([asudserver],[0.0.1],[khanton@yandex.ru])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADER([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_LANG_SOURCE([c++])

AM_MAINTAINER_MODE

m4_include([m4/acx_pthread.m4])
m4_include([m4/ax_cxx_check_lib.m4])
m4_include([m4/ax_boost_base.m4])
m4_include([m4/ax_boost_thread.m4])
m4_include([m4/ax_boost_system.m4])
m4_include([m4/ax_boost_program_options.m4])

# Checks for programs.
AC_PROG_LIBTOOL
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET

# Checks for libraries.
ACX_PTHREAD
AX_BOOST_BASE(1.39)
AX_BOOST_SYSTEM
AX_BOOST_THREAD
AX_BOOST_PROGRAM_OPTIONS

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h stdlib.h sys/socket.h sys/time.h syslog.h unistd.h memory.h netdb.h stdlib.h string.h])
AC_FUNC_ERROR_AT_LINE
AC_FUNC_MALLOC
AC_CHECK_FUNCS([gethostname memset socket strcasecmp strdup strncasecmp])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_STRUCT_TM

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AC_FUNC_LSTAT
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
AC_FUNC_MKTIME
AC_FUNC_STRFTIME
AC_CHECK_FUNCS([memset socket strcasecmp strdup strncasecmp endgrent endpwent memset socket strcasecmp strchr strerror strncasecmp])

# Get MySQL library and include locations
AC_ARG_WITH([mysql-include-path],
  [AS_HELP_STRING([--with-mysql-include-path],
    [location of the MySQL headers, defaults to /usr/include/mysql])],
  [MYSQL_CFLAGS="-I$withval"],
  [MYSQL_CFLAGS='-I/usr/include/mysql'])
AC_SUBST([MYSQL_CFLAGS])

AC_ARG_WITH([mysql-lib-path],
  [AS_HELP_STRING([--with-mysql-lib-path], [location of the MySQL libraries])],
  [MYSQL_LIBS="-L$withval -lmysqlclient_r"],
  [MYSQL_LIBS='-L/usr/lib/mysql -L/usr/lib64/mysql -lmysqlclient_r'])
AC_SUBST([MYSQL_LIBS])

# Get MySQL++ library and include locations
AC_ARG_WITH([mysqlxx-include-path],
  [AS_HELP_STRING([--with-mysqlxx-include-path],
    [location of the MySQL headers, defaults to /usr/include/mysql++])],
  [MYSQLXX_CPPFLAGS="-I$withval"],
  [MYSQLXX_CPPFLAGS='-I/usr/include/mysql++'])
AC_SUBST([MYSQLXX_CPPFLAGS])

AC_ARG_WITH([mysqlxx-lib-path],
  [AS_HELP_STRING([--with-mysqlxx-lib-path], [location of the MySQL libraries])],
  [MYSQLXX_LIBS="-L$withval -lmysqlpp"],
  [MYSQLXX_LIBS='-L/usr/lib/mysql++ -L/usr/lib64/mysql++ -lmysqlpp'])
AC_SUBST([MYSQLXX_LIBS])

AC_CONFIG_FILES([Makefile src/Makefile src/controller/Makefile])
AC_OUTPUT
